/**
 * Class for parsing json and generate SvgContainer and SvgElement objects
 * @class SvgConfigParser
 * @extends Class
 * @constructor
 * @param {object} config  See configuration attributes
 * @param {SVGElement} Dom svg element of the parent container
 * @param {SvgCanvas} The svg stage/canvas
 */
/**
 * The svg element type
 * @config type 
 * @type String
 */
/**
 * An array of config objects which represents the child elements
 * @config items 
 * @type Array
 */
/**
 * An config object with attributes of the svg element
 * @config attr 
 * @type Object
 */
/**
 * An config object with event listeners for the svg element
 * @config listeners 
 * @type Object
 */
/**
 * An config object which represents a child animation element
 * @config animate 
 * @type Object
 */
/**
 * An config object which represents a child animationTransform element
 * @config animateTransform 
 * @type Object
 */
/**
 * An config object which represents a child animationMotion element
 * @config animateMotion 
 * @type Object
 */
var SvgConfigParser = {
    svg: null,
    
    /**
     * @private
     * @method init
     * @memberOf SvgConfigParser
     */
    init: function(config, container, canvas) {
        var svg = canvas, 
            parse = function(o, c) {
                if (o && typeof(o)=="object" && o.type) {
                    var isContainer = (o.items && isArray(o.items));
                    var el = isContainer ? new SvgContainer(o.type, c, svg) : new SvgElement(o.type, c, svg);
                    if (o.attr) el.attr(o.attr);
                    if (isContainer) {
                        for (var i=0; i<o.items.length; i++) parse(o.items[i], el.dom);
                    }
                    if (o.listeners) {
                        for (var l in o.listeners) {
                            el.on(l, o.listeners[l], el);
                        }
                    }
                    if (o.animate) {
                        if (isArray(o.animate)) {
                            for (var i=0; i<o.animate.length; i++) el.animate(o.animate[i].attr ? o.animate[i].attr : {});
                        } else
                            el.animate(o.animate.attr ? o.animate.attr : {});
                        
                    }
                    if (o.animateTransform) {
                        if (isArray(o.animateTransform)) {
                            for (var i=0; i<o.animateTransform.length; i++) el.animateTransform(o.animateTransform[i].attr ? o.animateTransform[i].attr : {});
                        } else
                            el.animateTransform(o.animateTransform.attr ? o.animateTransform.attr : {});
                        
                    }
                    if (o.animateMotion) {
                        if (isArray(o.animateMotion)) {
                            for (var i=0; i<o.animateMotion.length; i++) el.animateMotion(o.animateMotion[i].attr ? o.animateMotion[i].attr : {});
                        } else
                            el.animateMotion(o.animateMotion.attr ? o.animateMotion.attr : {});
                        
                    }
                }
            };
        
        this.svg=canvas;
        parse(config, container);
    }   
    
};
SvgConfigParser = Class.extend(SvgConfigParser);